FROM golang:alpine AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOPROXY https://goproxy.cn,direct

WORKDIR /build/zero

RUN go mod init go-devops/app/user/cmd/api
RUN go mod tidy
COPY . .
COPY /etc /app/etc
RUN go build -ldflags="-s -w" -o /app/userapi app/user/cmd/api/userapi.go


FROM alpine

RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata
ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /app/userapi /app/userapi
COPY --from=builder /app/etc /app/etc

CMD ["./userapi", "-f", "etc/userapi.yaml"]
